package cn.stronglink.assetmanage.business.task.view.operate;

import android.os.Bundle;
import android.support.v4.app.Fragment;
import android.support.v4.app.FragmentManager;
import android.support.v4.app.FragmentTransaction;
import android.view.View;

import java.util.List;

import cn.stronglink.assetmanage.MainActivity;
import cn.stronglink.assetmanage.R;
import cn.stronglink.assetmanage.business.check.view.checked.CheckedAssetFragment;
import cn.stronglink.assetmanage.business.check.view.checked.CheckedListFragment;
import cn.stronglink.assetmanage.business.check.view.detail.CheckedDetailFragment;
import cn.stronglink.assetmanage.business.check.view.wait.WaitAssetFragment;
import cn.stronglink.assetmanage.business.inspection.view.PatrolDetail.PatrolDetailFragment;
import cn.stronglink.assetmanage.business.inspection.view.repairDetail.RepairDetailFragment;
import cn.stronglink.assetmanage.business.inspection.view.resiger.RepairRegisterFragment;
import cn.stronglink.assetmanage.business.inventory.view.count.InventoryCountFragment;
import cn.stronglink.assetmanage.business.inventory.view.detail.InventoryDetailFragment;
import cn.stronglink.assetmanage.business.task.adapter.TaskListAdapter;
import cn.stronglink.assetmanage.business.task.view.ITaskView;
import cn.stronglink.assetmanage.entity.Task;
import cn.stronglink.assetmanage.index.entity.PromissionEntity;
import cn.stronglink.assetmanage.utils.Constants;

/**
 * Created by chencongcong on 2018/6/18.
 */

public class TaskOpreateView implements ITaskView {
    private TaskListAdapter listAdapter;
    private List<Task> taskList;
    private Fragment currentFragment;
    public TaskOpreateView(Fragment fragment, View view, TaskListAdapter listAdapter) {
        this.listAdapter = listAdapter;
        this.currentFragment = fragment;
    }
    @Override
    public void setTaskListData(List<Task> taskListData) {
        if(listAdapter!=null){
            listAdapter.notifyDatasChanged(taskListData);
        }
        this.taskList = taskListData;
    }

    @Override
    public void showTaskAssetFragment(int postion) {
        Task task = taskList.get(postion);
        Fragment fragment = null;
        String tag = "";
        String title="";
        switch (task.getBusinessType()){
            case Constants.STATUS_ONE:
                //已入库列表
                fragment = new CheckedAssetFragment();
                tag = Constants.CHECK_IN_DETAIL_NO;
                title = "已入库";
                break;
            case Constants.STATUS_TWO:
                //未盘点列表
                fragment = new InventoryDetailFragment();
                tag = Constants.INVENTORY_DETAIL_NO;
                title="盘点详情";
                break;
            case Constants.STATUS_THREE:
                // 维修
                fragment = new RepairRegisterFragment();
                tag = Constants.SEARCH_REPAIR_NO;
                title="维修详情";
                break;
            case Constants.STATUS_FOUR:
                fragment = new PatrolDetailFragment();
                tag = Constants.PATROL_DETAIL_NO;
                title="巡检详情";
                break;
        }
        startFragment(fragment,task,tag,title);
    }
    private void startFragment(Fragment fragment,Task task,String tag,String title) {
//        FragmentManager fragmentManager = currentFragment.getActivity().getSupportFragmentManager();
//        FragmentTransaction transaction = fragmentManager.beginTransaction();
//        transaction.add(R.id.frame_business, fragment);
//        transaction.commit();
//        Bundle bundle=new Bundle();
//        bundle.putString(Constants.CHECK_IN_DETAIL_NO, task.getId_());
//        fragment.setArguments(bundle);
        MainActivity activity = (MainActivity) currentFragment.getActivity();
        PromissionEntity pe = new PromissionEntity();
        pe.setFragment(fragment);
        pe.setPosition(MainActivity.FRAGMENT_CUSTOM_ID);
        pe.setTitle(title);
        // 设置打开盘点详情后传递的参数
        Bundle bundle=new Bundle();
        bundle.putSerializable(tag, task.getId_());
        pe.setBundle(bundle);
        activity.onEventRegister(pe);
    }
}
